package com.okilo.online.app.tools.decoration

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration

/**
 * LinearSpacingItemDecoration
 * @Author wwdeng
 * @CreateTime: 2024/10/17 11:59
 * @Annotation：LinearLayoutManager 设置item的间隔
 */
class LinearSpacingItemDecoration(private val leftSpace: Int, private val rightSpace: Int, private val topSpace: Int, private val bottomSpace: Int) : ItemDecoration() {
    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        outRect.left = leftSpace
        outRect.right = rightSpace
        outRect.bottom = bottomSpace

        // Add top margin only for the first item to avoid double space between items
        if (parent.getChildAdapterPosition(view) == 0) {
            outRect.top = topSpace
        }
    }
}
